package com.muyu.danmo.service.impl;


import com.muyu.common.core.utils.DateUtils;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.danmo.domain.DanmoCollectFootprint;
import com.muyu.danmo.domain.DanmoCollectShellfish;
import com.muyu.danmo.mapper.DanmoCollectFootprintMapper;
import com.muyu.danmo.service.IDanmoCollectFootprintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 拾贝信息足迹Service业务层处理
 * 
 * @author yangle
 * @date 2024-11-06
 */
@Service
public class DanmoCollectFootprintServiceImpl implements IDanmoCollectFootprintService
{
    @Autowired
    private DanmoCollectFootprintMapper danmoCollectFootprintMapper;

    /**
     * 查询拾贝信息足迹
     * 
     * @param id 拾贝信息足迹主键
     * @return 拾贝信息足迹
     */
    @Override
    public DanmoCollectFootprint selectDanmoCollectFootprintById(Long id)
    {
        return danmoCollectFootprintMapper.selectDanmoCollectFootprintById(id);
    }

    /**
     * 查询拾贝信息足迹列表
     * 
     * @param danmoCollectFootprint 拾贝信息足迹
     * @return 拾贝信息足迹
     */
    @Override
    public List<DanmoCollectFootprint> selectDanmoCollectFootprintList(DanmoCollectFootprint danmoCollectFootprint)
    {
        return danmoCollectFootprintMapper.selectDanmoCollectFootprintList(danmoCollectFootprint);
    }

    /**
     * 新增拾贝信息足迹
     * 
     * @param danmoCollectFootprint 拾贝信息足迹
     * @return 结果
     */
    @Transactional
    @Override
    public int insertDanmoCollectFootprint(DanmoCollectFootprint danmoCollectFootprint)
    {
        danmoCollectFootprint.setCreateTime(DateUtils.getNowDate());
        int rows = danmoCollectFootprintMapper.insertDanmoCollectFootprint(danmoCollectFootprint);
        insertDanmoCollectShellfish(danmoCollectFootprint);
        return rows;
    }

    /**
     * 修改拾贝信息足迹
     * 
     * @param danmoCollectFootprint 拾贝信息足迹
     * @return 结果
     */
    @Transactional
    @Override
    public int updateDanmoCollectFootprint(DanmoCollectFootprint danmoCollectFootprint)
    {
        danmoCollectFootprint.setUpdateTime(DateUtils.getNowDate());
        danmoCollectFootprintMapper.deleteDanmoCollectShellfishById(danmoCollectFootprint.getId());
        insertDanmoCollectShellfish(danmoCollectFootprint);
        return danmoCollectFootprintMapper.updateDanmoCollectFootprint(danmoCollectFootprint);
    }

    /**
     * 批量删除拾贝信息足迹
     * 
     * @param ids 需要删除的拾贝信息足迹主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteDanmoCollectFootprintByIds(Long[] ids)
    {
        danmoCollectFootprintMapper.deleteDanmoCollectShellfishByIds(ids);
        return danmoCollectFootprintMapper.deleteDanmoCollectFootprintByIds(ids);
    }

    /**
     * 删除拾贝信息足迹信息
     * 
     * @param id 拾贝信息足迹主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteDanmoCollectFootprintById(Long id)
    {
        danmoCollectFootprintMapper.deleteDanmoCollectShellfishById(id);
        return danmoCollectFootprintMapper.deleteDanmoCollectFootprintById(id);
    }

    /**
     * 新增拾贝信息信息
     * 
     * @param danmoCollectFootprint 拾贝信息足迹对象
     */
    public void insertDanmoCollectShellfish(DanmoCollectFootprint danmoCollectFootprint)
    {
        List<DanmoCollectShellfish> danmoCollectShellfishList = danmoCollectFootprint.getDanmoCollectShellfishList();
        Long id = danmoCollectFootprint.getId();
        if (StringUtils.isNotNull(danmoCollectShellfishList))
        {
            List<DanmoCollectShellfish> list = new ArrayList<DanmoCollectShellfish>();
            for (DanmoCollectShellfish danmoCollectShellfish : danmoCollectShellfishList)
            {
                danmoCollectShellfish.setId(id);
                list.add(danmoCollectShellfish);
            }
            if (list.size() > 0)
            {
                danmoCollectFootprintMapper.batchDanmoCollectShellfish(list);
            }
        }
    }
}
